
checkLogin();

var login = getCache(login_key);
var mobile = login.mobile;
if(isEmpty(mobile)){
    $('.mobile_detail').html('<span class="bind_mobile">：请绑定手机号</span>');
    $('.bind_mobile').bind('click',function () {
        $('#myform_mobile').show();
    });
}else {
    $('.mobile_detail').text('：'+mobile);
}


var success = function (res) {
    var info = res.data.info;
   if(!isEmpty(info) && !isEmpty(info.avatarurl)){
       $('.member-img').attr('src',info.avatarurl);
       $('#nickname').text(info.nickname);
       $('#mid').text(info.mid);
   }else {
       var src = 'image/order/default_user_portrait.gif';
       $('.member-img').css('src',src);
   }
    /*var html1 = template('daohang',info);
    $('#daohang_content').append(html1);*/

    //给导航部分数据赋值
    if(!isEmpty(info)){
        $('#bill_num').text(info.total_waterbill_num);
        $('#bucket_num').text(info.total_bucket_num);
        $('#deposit').text(info.deposit);
    }

}

getData(member_info,comParams(),success);

$('.img_cuo').bind('click',function () {
    $('.show_alert').hide();
})

$('.get_code').bind('click',function () {

    var mobile = $('.mobile').val();
    if (mobile == undefined || mobile == null || mobile == '') {
        malert('请填写联系方式');
        return;
    }
    var success = function (res) {
        console.log(res)
        var info = res.sms_time;

        $('.get_code').text(info + 's');
        var intervarId = null;

        function count_down() {
            info--;
            if (info <= 0) {
                clearInterval(intervarId);
                $('.get_code').removeClass('mui-disabled').removeAttr('disabled');
                $('.get_code').text('请重新获取');
                return;
            }
            $('.get_code').text(info + 's');
        }

        intervarId = setInterval(function () {
            count_down();
        }, 1000);


    }
    getData(member_sms_captcha, combineParams({mobile: mobile}), success);
})

var is_mobile = function(e) {
    var status = true;
    if (!(/^1\d{10}$/.test( $(e).val()))){
        status = false;
    }
    return {
        status: status, // or false
        message: '请填写正确的手机号'
    };
}

var ajaxOption = {
    url: member_add_information,
    method: 'POST',
    data: comParams(),
    success: function (res) {
        //保存成功  将修改的电话追加到 缓存中
        var mobile = $('.mobile').val();
        var login_text = getCache(login_key);
        if(!isEmpty(login_text) && isEmpty(login_text.mobile)){
            login_text.mobile = mobile;
            console.log(login_text)
            setCache(login_key, login_text);
        }
        var mobiless = getCache(login_key).mobile;
        $('.show_alert').hide();
        $('.mobile_detail').html('');
        $('.mobile_detail').text('：'+mobiless);
    }
}

checkform($('#myform_mobile'), ajaxOption);
